package com.corpgovernment.common.dataloader;

import com.corpgovernment.api.common.sdk.SupplierInfoService;
import com.corpgovernment.common.base.JSONResult;
import com.corpgovernment.common.dto.EmployeeOpenCardReq;
import com.corpgovernment.common.dto.GetEmployeeOpenCardReq;
import com.corpgovernment.common.dto.GetEmployeeOpenCardRsp;
import com.corpgovernment.common.dto.SupplierCompanyDto;
import com.corpgovernment.common.feignRpc.CommonOrganizationClient;
import com.ctrip.corp.obt.generic.utils.JsonUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Objects;

@Slf4j
@Service("commonOrganizationDataloader")
public class CommonOrganizationDataloader {

    @Autowired
    private CommonOrganizationClient commonOrganizationClient;
    @Autowired(required = false)
    private SupplierInfoService supplierInfoService;

    public GetEmployeeOpenCardRsp getEmployeeOpenCardInfo(GetEmployeeOpenCardReq request){
        JSONResult<GetEmployeeOpenCardRsp> data = commonOrganizationClient.getEmployeeOpenCardInfo(request);
        if (Objects.isNull(data) || !data.isSUCCESS()){
            log.info("getEmployeeOpenCardInfo error:{}", JsonUtils.toJsonString(data));
            return null;
        }
        return data.getData();
    }

    public void employeeOpenCard(EmployeeOpenCardReq request){
        JSONResult<GetEmployeeOpenCardRsp> data = commonOrganizationClient.employeeOpenCard(request);
        if (Objects.isNull(data) || !data.isSUCCESS()){
            log.info("getEmployeeOpenCardInfo error:{}", JsonUtils.toJsonString(data));
            return;
        }
        return;
    }

    public List<SupplierCompanyDto> getSupplierCompanySoa(){
        JSONResult<List<SupplierCompanyDto>> data = commonOrganizationClient.getSupplierCompanySoa();
        if (Objects.isNull(data) || !data.isSUCCESS()){
            log.info("getSupplierCompanySoa error:{}", JsonUtils.toJsonString(data));
            return Collections.emptyList();
        }
        return data.getData();
    }

    public List<SupplierCompanyDto> getSupplierCompanySDK(){
        List<SupplierCompanyDto> data = supplierInfoService.getSupplierCompanySoa();
        return data;
    }

    public GetEmployeeOpenCardRsp getEmployeeOpenCardRsp(GetEmployeeOpenCardReq request){
        return supplierInfoService.getEmployeeOpenCard(request);
    }
}
